package tech.yangzhijie.basic.java04;

public class Java0504 {
    public static void main(String[] args) {
        Circle c1 = new Circle(new Point(1,1),1);
        Circle c2 = new Circle(new Point(4,1),2);
        Circle c3 = new Circle(new Point(7,1),3);
        System.out.println("c1的面积为："+c1.area());
        System.out.println("c2的面积为："+c2.area());
        System.out.println("c3的面积为："+c3.area());
        System.out.println("c1的周长为："+c1.perimeter());
        System.out.println("c2的周长为："+c2.perimeter());
        System.out.println("c3的周长为："+c3.perimeter());
        System.out.println("c1 与 c2 的关系："+Circle.whetherToIntersect(c1,c2));//相切
        System.out.println("c1 与 c3 的关系："+Circle.whetherToIntersect(c1,c3));//相离
        System.out.println("c2 与 c3 的关系："+Circle.whetherToIntersect(c2,c3));//相交

        Line line1 = new Line(new Point(1, 2), new Point(4, 2));
        Line line2 = new Line(new Point(2, 3), new Point(4, 1));
        Line line3 = new Line(new Point(1, 1), new Point(2, 2));

        System.out.println("c1 与 line1 的位置关系："+c1.givenThePositionOfTheLine(line1));//与c1相切
        System.out.println("c1 与 line2 的位置关系："+c1.givenThePositionOfTheLine(line2));//与c1相离
        System.out.println("c1 与 line3 的位置关系："+c1.givenThePositionOfTheLine(line3));//与c1相交
    }

}

class Circle{
    private Point centerOfMind;
    private double radius;

    public Circle() {
    }

    public Circle(Point centerOfMind, double radius) {
        this.centerOfMind = centerOfMind;
        this.radius = radius;
    }

    public double area(){
        return Math.PI * Math.pow(radius,2);
    }

    public double perimeter(){
        return 2 * Math.PI * radius;
    }

    public static String whetherToIntersect(Circle circle1,Circle circle2){
        double a = Point.distanceBetweenTwoPoints(circle1.centerOfMind, circle2.centerOfMind);
        double b = circle1.radius + circle2.radius;
        if(a > b){
            return "相离";
        }else if(a == b){
            return "相切";
        }
        return "相交";
    }

    public String givenThePositionOfTheLine(Line line){
        double d = line.givenTheDistanceFromThePointToTheLine(centerOfMind);
        if(d == radius){
            return "相切";
        }else if(d > radius){
            return "相离";
        }
        return "相交";
    }
}
